package com.roadshare.ciw.queue;

import java.util.List;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Component;

import com.roadshare.ciw.common.JsonUtil;
import com.roadshare.ciw.email.entity.PushEmailEntity;
import com.roadshare.ciw.service.SendInformationService;

/**
 * 队列消息监听器. <br>
 * 类详细说明.
 * <p>
 * Copyright: Copyright (c) 2016年5月10日 上午11:11:07
 * <p>
 * Company: 苏州罗想软件有限公司
 * <p>
 * 
 * @author bing.zhou@roadshare.com
 * @version 1.0.0
 */
@Component
public class QueueReceiver1 implements MessageListener {

	private final Logger log = Logger.getLogger(QueueReceiver1.class);

	// @Override
	public void onMessage(Message message)
	{
		try
		{第二次
			System.out.println("QueueReceiver222接收到消息:" + ((TextMessage) message).getText());
			log.debug("发送邮件了！");
			String msg = ((TextMessage) message).getText();
			if (msg.contains("userName"))
			{
				return;
			}
			List<Object> listObj = JsonUtil.getList4Json(msg, PushEmailEntity.class);

			for (Object oo : listObj)
			{
				PushEmailEntity email = (PushEmailEntity) oo;
				SendInformationService.sendEmailMethod(email);
			}
		}
		catch (JMSException e)
		{
			e.printStackTrace();
		}
	}
}
